package graphic;

import input.Input;
import klient.Klient;
import objects.Dir;
import static objects.Dir.DOWN;
import static objects.Dir.UP;
import org.lwjgl.input.Keyboard;


/**
 *  
 * @author Marcin & Bartek
 * 
 * @description Defines actions for camera usage
 */
public final class Camera {
    private Camera(){}
    public static float x=0,y=0,height=1f,degree=1f,bdegree=0.f;
    public static float sensitive=0.4f;
    public static float rotsensitive=0.03f;
    
    public static float ty=0;
    
    public static float n=0,nx=0,ny=0,nz=0;
    
    public static boolean change=true;
    
    public static void getInput(){
        if(Input.isKeyDown(Keyboard.KEY_W)) move(Dir.UP);
        if(Input.isKeyDown(Keyboard.KEY_S)) move(Dir.DOWN);
        if(Input.isKeyDown(Keyboard.KEY_A)) move(Dir.LEFT);
        if(Input.isKeyDown(Keyboard.KEY_D)) move(Dir.RIGHT);
        if(Input.isKeyDown(Keyboard.KEY_Q)) brot(Dir.LEFT);
        if(Input.isKeyDown(Keyboard.KEY_E)) brot(Dir.RIGHT);
        if(Input.isKeyDown(Keyboard.KEY_R)) lift(Dir.UP);
        if(Input.isKeyDown(Keyboard.KEY_F)) lift(Dir.DOWN);
        if(Input.isKeyDown(Keyboard.KEY_T)) moveVert(Dir.UP);
        if(Input.isKeyDown(Keyboard.KEY_G)) moveVert(Dir.DOWN);
        rot(Input.Mwhell);
    }
    
    public static void setXY(float nx, float ny){
        change=true;
        x=nx;
        y=ny;
    }
    
    public static void brot(Dir d){
        change=true;
        if(d==Dir.RIGHT) bdegree+=rotsensitive;
        else bdegree-=rotsensitive;
    }
    
    public static void rot(int nr){
        change=true;
        nr/=120;
        float ang=nr*rotsensitive;
        degree+=ang;
    }
    
    public static void move(Dir d){
        change=true;
        switch(d){
            case UP:
                y-=(nz/n)*sensitive;
                x-=(nx/n)*sensitive;
                break;
            case DOWN:
                y+=(nz/n)*sensitive;
                x+=(nx/n)*sensitive;
                break;
            case LEFT:
                y+=(nx/n)*sensitive;
                x-=(nz/n)*sensitive;
                break;
            case RIGHT:
                y-=(nx/n)*sensitive;
                x+=(nz/n)*sensitive;
                break;
        }
    }
    
    public static void moveVert(Dir d){
        change=true;
        if(d == UP)
            ty+=sensitive;
        else
            ty-=sensitive;
    }
    
    public static void lift(Dir d){
        change=true;
        switch(d){
            case UP:
                height+=sensitive;
                break;
            case DOWN:
                height-=sensitive;
                break;
        }
    }
    public static void addHeight(float value){
        change=true;
       height+=value;
    }
    public static void refresh(){
        if(change){
            ny= height*(float)Math.sin(degree);
            n= height*(float)Math.cos(degree);
            nx= n*(float)Math.cos(bdegree);
            nz= n*(float)Math.sin(bdegree);
            change=false;
        }
        Graphic.e.setCam(x,y,nx,ny,nz,ty);
    }
}
